cmake_minimum_required(VERSION 3.16)

set(CMAKE_SYSTEM_NAME Generic)

#设置工程名称
project(cmake_test)


set(${CMAKE_TOOLCHAIN_FILE} $ENV{IDF_PATH}/tools/cmake/toolchain-esp32.cmake)
include($ENV{IDF_PATH}/tools/cmake/toolchain-esp32.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain.cmake)


#包含IDF CMAKE API
include($ENV{IDF_PATH}/tools/cmake/idf.cmake)

#添加idf编译项目
idf_build_process("esp32"
                COMPONENTS freertos esptool_py driver esp_timer esp_adc
                SDKCONFIG ${CMAKE_CURRENT_LIST_DIR}/sdkconfig
                BUILD_DIR ${CMAKE_BINARY_DIR})

include(${CMAKE_CURRENT_LIST_DIR}/cmake/src.cmake)
set(Libs idf::freertos idf::spi_flash idf::driver idf::esp_timer idf::esp_adc)

include_directories(${Inc})

#添加编译可执行程序
set(elf_file ${CMAKE_PROJECT_NAME}.elf)
add_executable(${elf_file} ${Src})


target_link_libraries(${elf_file} ${Libs})
    # Attach additional targets to the executable file for flashing,
    # linker script generation, partition_table generation, etc.
idf_build_executable(${elf_file})
